﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Classes;

namespace Pager
{
    public partial class Default : Page
    {
        /*public Default()
        {
            Load += Page_Load;
        }*/

        protected void Page_Load(object sender, EventArgs e) {
            if (IsPostBack) { return; }
            CarregaGridDataSet();
            CarregaGridDataTable();
            CarregaGridProcedure();
            CarregaDTO();
            if (Request["ID"] != null) {
                if (Request["ID"].Equals("1")) {
                    Controle.Usuario.Gravar(null, DateTime.Now, "Ricardo", "rluiz", 8888888);
                }
            }
        }

        #region CarregaGridDataSet
        /// <summary>
        /// CarregaGridDataSet.
        /// </summary>
        /// <returns></returns>        
        private void CarregaGridDataSet()
        {
            try
            {
                gdvDataSet.DataSource = Controle.Usuario.GetDataSet(DateTime.Parse("01/01/2011"), DateTime.Now);
                gdvDataSet.DataBind();
            }
            catch (Exception ex)            
            {
                throw ex;
            }
        }
        #endregion
        
        #region CarregaGridDataTable
        /// <summary>
        /// CarregaGridDataTable.
        /// </summary>
        /// <returns></returns>        
        private void CarregaGridDataTable()
        {
            try
            {
                gdvDataTable.DataSource = Controle.Usuario.GetDataTable();
                gdvDataTable.DataBind();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region CarregaGridDataTable
        /// <summary>
        /// CarregaGridDataTable.
        /// </summary>
        /// <returns></returns>        
        private void CarregaGridProcedure()
        {
            try
            {
                GridView3.DataSource = Controle.Usuario.GetProcedure();
                GridView3.DataBind();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion       

        #region CarregaDTO
        /// <summary>
        /// CarregaGridDataTable.
        /// </summary>
        /// <returns></returns>        
        private void CarregaDTO()
        {
            try
            {
                gdvDTO.DataSource = Controle.Usuario.GetDTO();
                gdvDTO.DataBind();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion       

        protected void GridViewPageIndexChanging(object sender, GridViewPageEventArgs e) {
            ((GridView)sender).PageIndex = e.NewPageIndex;
            ((GridView)sender).DataBind();
        }
    }

}